package com.yjt.fresh.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wzgiceman.rxretrofitlibrary.retrofit_rx.http.HttpManager;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.listener.HttpOnNextListener;
import com.yjt.fresh.R;
import com.yjt.fresh.adpater.AdpRvExpress;
import com.yjt.fresh.api.ApiGetExpressInfo;
import com.yjt.fresh.base.BaseSimpleActivity;
import com.yjt.fresh.bean.BeanExpress;
import com.yjt.fresh.constant.MyConstants;
import com.yjt.fresh.utils.PreferenceManager;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by UPC on 2018/8/11.
 */

public class AtyCheckExpress extends BaseSimpleActivity {
    @BindView(R.id.rlBack)
    RelativeLayout mRlBack;
    @BindView(R.id.tvAtyExpressCompany)
    TextView mTvCompany;
    @BindView(R.id.tvAtyExpressNum)
    TextView mTvNum;
    @BindView(R.id.rvAtyExpress)
    RecyclerView mRv;

    private AdpRvExpress mAdpRvExpress;

    @Override
    protected int getContentView() {
        return R.layout.app_aty_express;
    }

    @Override
    protected void initViews() {
        ButterKnife.bind(this);
    }

    @Override
    protected void initEvent() {
        initRv();
        initClick();
        getData();
    }

    private void initClick() {
        mRlBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    HttpOnNextListener<BeanExpress> mExpressListener = new HttpOnNextListener<BeanExpress>() {
        @Override
        public void onNext(BeanExpress beanExpress) {
            mAdpRvExpress.setNewData(beanExpress.getExpressList());
            mTvCompany.setText("物流公司: "+beanExpress.getEXPRESS_NAME());
            mTvNum.setText("运单号码: "+beanExpress.getWAYBILL_NO());
        }

        @Override
        public void onReLogin() {
            toLogin();
        }
    };

    private void getData() {
        ApiGetExpressInfo apiGetExpressInfo = new ApiGetExpressInfo(mExpressListener,mContext,true,false,false);
        Map<String,Object> map = new HashMap<>();
        map.put("SESSION_ID", PreferenceManager.getInstance().getUserInfo().getSESSION_ID());
        map.put("ORDERS_ID",getIntent().getStringExtra(MyConstants.ORDER_ID));
        apiGetExpressInfo.setMap(map);
        HttpManager.getInstance().doHttpDeal(apiGetExpressInfo);
    }

    private void initRv() {
        LinearLayoutManager manager = new LinearLayoutManager(mContext);
        mRv.setLayoutManager(manager);
        List<BeanExpress.ExpressListBean> expressList = new ArrayList<>();
        mAdpRvExpress = new AdpRvExpress(R.layout.app_recycle_item_express, expressList);
        mRv.setAdapter(mAdpRvExpress);
    }
}
